#ifndef FITNESS_BINARIA_CU
#define FITNESS_BINARIA_CU

#include "fitnessBinaria.cuh"
#include "../utils/global.cuh"
#include "../utils/cuPrintf.cu"

float calcularFitnessBinariaCPU(bool* poblacion, int posicion){
	float fitness = 0;
	for(int i = 0; i < cantGenesEnCromosoma; i++){
		fitness = fitness + poblacion[posicion + i];
	}
	return fitness;
}

__device__ float calcularFitnessBinariaGPU(bool* poblacion, int posicion){
	float fitness = 0;
	for(int i = 0; i < cantGenesEnCromosomaDevice; i++){
	  fitness = fitness + poblacion[posicion + i];
	}
	return fitness;
}

__global__ void calcularFitnessBinariaGPUGen(bool* poblacion, float* vectorFitness, float* fitnessOrdenadoDevice){
	int posicionIndividuo = blockIdx.y * cantGenesEnCromosomaDevice;
	int posicionFitness = blockIdx.y;
	float fitness = 0;
	for(int i = posicionIndividuo + threadIdx.y; i < posicionIndividuo + cantGenesEnCromosomaDevice; i = i + cantHilosBloqueDevice){
	  fitness = fitness + poblacion[i];
	}
	atomicAdd(&(vectorFitness[posicionFitness]), fitness);
	fitnessOrdenadoDevice[posicionFitness] = vectorFitness[posicionFitness];
}

#endif

